package com.demo.web;

import com.demo.dao.ApplySendMapper;
import com.demo.dto.BaseResult;
import com.demo.dto.ListResult;
import com.demo.dto.Pagination;
import com.demo.vo.ApplySendVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/applySend")
public class ApplySendController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ApplySendMapper dao;


    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult query(ApplySendVo arg) {
        List<ApplySendVo> list = dao.queryByPage(arg);
        int total = dao.queryCountByPage(arg);
        Pagination page = new Pagination(arg.getPage(), total, arg.getSize());
        ListResult res = new ListResult(true, list);
        res.setPage(page);
        return res;
    }
    /***
     * 审核
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/check", method = RequestMethod.POST)
    public BaseResult check(ApplySendVo arg) {
        int list = dao.updateByPrimaryKeySelective(arg);
        if (list == 1) {
            return new BaseResult(true, "操作成功");
        }else{
            return new BaseResult(false, "操作失败",500);
        }
    }
}
